﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NB.MGJ.Model;
using NB.MGJ.Common.Utility;

namespace NB.MGJ.Service.Origins
{
    public class MaterialFactor
    {


 
        private string materialName = "";
        private OriginsMaterialService _OriginsMaterialService;
        private OriginsModuleSEService _OriginsModuleSEService;
        private OriginsModuleService _OriginsModuleService;
        private OriginsNavService _OriginsNavService;
        private LogOnUserModel _logOnUser;

        public MaterialFactor(LogOnUserModel logOnUser)
        {
            _OriginsMaterialService = new OriginsMaterialService();
            _OriginsModuleSEService = new OriginsModuleSEService();
            _OriginsModuleService = new OriginsModuleService();
            _OriginsNavService = new OriginsNavService();
            _logOnUser = logOnUser;
        }




        /// <summary>
        /// 创建素材
        /// </summary>
        /// <param name="Version">版本号</param>
        /// <param name="Type">0应用素材 1体验素材</param>
        /// <returns></returns>
        public int Create(Origins_Material model)
        {
            this.materialName = model.MaterialName;
            switch (model.MaterialType)
            {
                case 0:
                    return CreateStandardEdition(model);
                case 1:
                    return CreateGoldEdition(model);
                case 2:
                    return CreatePlatinumEdition(model);
                case 3:
                    return CreateDiamondEdition(model);
                default:
                    break;
            }
            return 0;
        }


        public int CreateStandardEdition(Origins_Material model)
        {

            var result = _OriginsMaterialService.Add(model);
            //标准版素材新增默认新增绑定一个标准版模块
            if (result > 0)
            {
                model.MaterialId = result;
                var modulseId = ModuleSEAdd();
                model.ModuleId = modulseId;
                _OriginsMaterialService.Update(model);

            }
            return result;

        }

        public int CreateGoldEdition(Origins_Material model)
        {
            var result = _OriginsMaterialService.Add(model);
            //黄金版素材新增默认新增绑定一个黄金版模块【标准版和黄金版公用一张表】
            if (result > 0)
            {
                model.MaterialId = result;
                var modulseId = ModuleSEAdd();
                model.ModuleId = modulseId;
                _OriginsMaterialService.Update(model);

            }
            return result;

        }
        public int CreatePlatinumEdition(Origins_Material model)
        {
            var result = _OriginsMaterialService.Add(model);
            return result;
        }

        public int CreateDiamondEdition(Origins_Material model)
        {
            var result = _OriginsMaterialService.Add(model);
            if (result> 0)
            {
                model.MaterialId = result;
                var modulId = NavModuleAdd();
                model.ModuleId = modulId;
                _OriginsMaterialService.Update(model);
            }
            return result;
        }


        public int ModuleSEAdd()
        {
            Origins_ModuleSE model = new Origins_ModuleSE();

            model.ChangeDate = DateTime.Now;
            model.ChangeLoginId = _logOnUser.UserID;
            model.ChangeLoginName = _logOnUser.LoginName;
            var result = _OriginsModuleSEService.Add(model);
            return result;
        }



        public int NavModuleAdd()
        {
            Origins_Module model = new Origins_Module();

            model.ChangeDate = DateTime.Now;
            model.ChangeLoginID = _logOnUser.UserID;
            model.ChangeLoginName = _logOnUser.LoginName;
            var result = _OriginsModuleService.Add(model);
            return result;
        }





    }

}
